package com.topwater.topwater.utils;


import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;

import java.lang.reflect.Field;
import java.util.List;
import java.util.stream.Collectors;
/**
*胡文 qq:986776
 *自定义生成器制造
*/
@Configuration //标记配置类
@EnableOpenApi//开启在线接口文档
public class Swagger3Config {
    //@Value("${swagger.enable}")
    private Boolean enable=true;
    //@Autowired
    //TypeResolver resolver;
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30).pathMapping("/")
                // 定义是否开启swagger，false为关闭，可以通过变量控制
//注意: springboot 超过2.3.1.RELEASE   加入 spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
                .enable(enable)
                .groupName("扫墓系统_接口") //右上角下拉框
                .apiInfo(new ApiInfoBuilder()
                        .title("标题：扫墓系统_接口文档")
                        .description("描述：用于管理集团旗下公司的人员信息,具体包括Hero烈士,Towns乡镇模块...")
                        .contact(new Contact("胡文", "主页无", "986776@qq.com"))
                        .version("版本号:3.0")
                        .build())
                // .additionalModels( resolver.resolve(Hero.class),resolver.resolve(Towns.class) )  //显示实体类
                .select()
               .apis(RequestHandlerSelectors.basePackage("com.situ"))
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //.apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class))
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .paths(PathSelectors.regex("/error.*").negate())// 错误路径不监控
                .build();
    }

    @Bean
    public Docket createRestApi2() {
        return new Docket(DocumentationType.OAS_30).pathMapping("/")
                // 定义是否开启swagger，false为关闭，可以通过变量控制
//注意: springboot 超过2.3.1.RELEASE 不兼容
                .enable(enable)
                .groupName("相亲_接口")
                .apiInfo(new ApiInfoBuilder()
                        .title("标题：相亲系统_接口文档")
                        .description("描述：用于管理集团旗下男士婚姻问题..")
                        .contact(new Contact("胡文", "主页无", "986776@qq.com"))
                        .version("版本号:3.0")
                        .build())
                // .additionalModels( resolver.resolve(Hero.class),resolver.resolve(Towns.class) )
                .select()
              //  .apis(RequestHandlerSelectors.basePackage("com.hw"))
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //.apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class))
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

}
